package com.geologyoa.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.DecimalFormat;
import java.util.Iterator;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.XMLWriter;

import com.geologyoa.domain.Wpdj01;
import com.geologyoa.service.SystemManager;
import com.geologyoa.service.SystemManagerImpl;

public class SerachWpdj01Servlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
         doPost(request,response);
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		SystemManager sys=new SystemManagerImpl();
		
		String WPDJ0102=request.getParameter("WPDJ0102");//危评统一编号
		String WPDJ0103=request.getParameter("WPDJ0103");//项目所在市
		String WPDJ0104=request.getParameter("WPDJ0104");//项目所在区/县
		String WPDJ0105=request.getParameter("WPDJ0105");//年份
		String WPDJ0107=request.getParameter("WPDJ0107");//评估报告名称
		String WPDJ0108=request.getParameter("WPDJ0108");//评估级别
		String WPDJ0111=request.getParameter("WPDJ0111");//用地性质
		String WPDJ0113min=request.getParameter("WPDJ0113min");//项目经费最小值
		String WPDJ0113max=request.getParameter("WPDJ0113max");//项目经费最大值
		String WPDJ0114=request.getParameter("WPDJ0114");//建设单位
		String WPDJ0116=request.getParameter("WPDJ0116");//评估单位
		String WPDJ0119s=request.getParameter("WPDJ0119s");//评审时间起
		String WPDJ0119e=request.getParameter("WPDJ0119e");//评审时间止
		//////add by cuiyi 20130509 
		String WPDJ0122s = request.getParameter("WPDJ0122s");//备案时间起
		String WPDJ0122e = request.getParameter("WPDJ0122e");//备案时间止
		String WPDJ0118 = request.getParameter("WPDJ0118");//评估资质级别 0 甲级、乙级、丙级
		/*WPDJ0122s = "";
		WPDJ0122e = "";
		WPDJ0118 = "";*/
		List<Wpdj01> wpdjList=sys.SerachWpdj(WPDJ0102,WPDJ0103, WPDJ0104, WPDJ0105, WPDJ0107, WPDJ0108, WPDJ0111, WPDJ0113min, WPDJ0113max, WPDJ0114, WPDJ0116, WPDJ0119s, WPDJ0119e, WPDJ0122s, WPDJ0122e, WPDJ0118);
		Document document=DocumentHelper.createDocument();
		if(wpdjList!=null)
		{
			Element fwlistElement =document.addElement("wpdjList");
			fwlistElement.addAttribute("size", (new StringBuilder(String.valueOf(wpdjList.size()))).toString());
			Wpdj01 wpdj01;
			Element fwElement;
			for(Iterator iterator=wpdjList.iterator();iterator.hasNext();)
			{
				wpdj01 = (Wpdj01)iterator.next();
				fwElement=fwlistElement.addElement("wpdjInfo");
				fwElement.addAttribute("WPDJ0101", wpdj01.getWpdj0101().toString());
				fwElement.addAttribute("WPDJ0102", wpdj01.getWpdj0102());
				fwElement.addAttribute("WPDJ0103", wpdj01.getWpdj0103());
				fwElement.addAttribute("WPDJ0104", wpdj01.getWpdj0104());
				fwElement.addAttribute("WPDJ0105", wpdj01.getWpdj0105());
				fwElement.addAttribute("WPDJ0106", wpdj01.getWpdj0106());
				fwElement.addAttribute("WPDJ0107", wpdj01.getWpdj0107());
				fwElement.addAttribute("WPDJ0108", wpdj01.getWpdj0108());
				fwElement.addAttribute("WPDJ0109", new DecimalFormat("0.00").format(wpdj01.getWpdj0109()));
				fwElement.addAttribute("WPDJ0110", new DecimalFormat("0.00").format(wpdj01.getWpdj0110()));
				fwElement.addAttribute("WPDJ0111", wpdj01.getWpdj0111());
				fwElement.addAttribute("WPDJ0112", wpdj01.getWpdj0112());
				fwElement.addAttribute("WPDJ0113", new DecimalFormat("0.00").format(wpdj01.getWpdj0113()));
				fwElement.addAttribute("WPDJ0114", wpdj01.getWpdj0114());
				fwElement.addAttribute("WPDJ0115", wpdj01.getWpdj0115());
				fwElement.addAttribute("WPDJ0116", wpdj01.getWpdj0116());
				fwElement.addAttribute("WPDJ0117", wpdj01.getWpdj0117());
				fwElement.addAttribute("WPDJ0118", wpdj01.getWpdj0118());
				fwElement.addAttribute("WPDJ0119", wpdj01.getWpdj0119());
				fwElement.addAttribute("WPDJ0120", wpdj01.getWpdj0120());
				fwElement.addAttribute("WPDJ0121", wpdj01.getWpdj0121());
				fwElement.addAttribute("WPDJ0122", wpdj01.getWpdj0122());
				fwElement.addAttribute("WPDJ0123", wpdj01.getWpdj0123());
				fwElement.addAttribute("WPDJ0124", wpdj01.getWpdj0124());
				fwElement.addAttribute("WPDJ0125", wpdj01.getWpdj0125());
				fwElement.addAttribute("WPDJ0126", wpdj01.getWpdj0126());
				fwElement.addAttribute("WPDJ0127", wpdj01.getWpdj0127());
				fwElement.addAttribute("WPDJ0128", wpdj01.getWpdj0128());
				fwElement.addAttribute("WPDJ0129", wpdj01.getWpdj0129());
				fwElement.addAttribute("WPDJ0130", wpdj01.getWpdj0130());
				fwElement.addAttribute("WPDJ0131", wpdj01.getWpdj0131());
				fwElement.addAttribute("WPDJ0132", new DecimalFormat("0.0000").format(wpdj01.getWpdj0132()));
				fwElement.addAttribute("WPDJ0133", new DecimalFormat("0.0000").format(wpdj01.getWpdj0133()));
				fwElement.addAttribute("WPDJ0134", wpdj01.getWpdj0134());
				fwElement.addAttribute("WPDJ0114name", wpdj01.getWpdj0114name());
				fwElement.addAttribute("WPDJ0116name", wpdj01.getWpdj0116name());
			}
		}
		StringWriter xmlout = new StringWriter();
		XMLWriter output = new XMLWriter(xmlout);
		output.write(document);
		response.setContentType("text/html;charset=utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Expires", "0");
		response.setHeader("Pragma", "No-cache");
		response.getWriter().write(xmlout.toString());
	}

}
